﻿using System.Collections.Generic;
using STT.Debug;

namespace STT.Parser {
    // Token: 0x02000026 RID: 38
    internal class Data_Member : SymbolGenericFormat {
        // Token: 0x0400017E RID: 382

        // Token: 0x0400017C RID: 380

        // Token: 0x0400017D RID: 381

        // Token: 0x0400017F RID: 383

        // Token: 0x060000BA RID: 186 RVA: 0x00007CF8 File Offset: 0x00006CF8
        public Data_Member(StartBlock _block_parent, SymData _sym_data_member, ModuleSymbols _mod_sym) :
            base(_block_parent, _block_parent.level) {
            mod_sym         = _mod_sym;
            sym_data_member = _sym_data_member;
            list_typeid     = new List<uint>();
            Create_list_type();
            var firstSymType = GetFirstSymType();
            UniqueName = firstSymType.UniqueName;
            if (UniqueName != null) block_parent.local_dependency = true;
        }

        // Token: 0x1700000E RID: 14
        // (get) Token: 0x060000AE RID: 174 RVA: 0x00007B1C File Offset: 0x00006B1C
        public ModuleSymbols mod_sym { get; }

        // Token: 0x1700000F RID: 15
        // (get) Token: 0x060000AF RID: 175 RVA: 0x00007B24 File Offset: 0x00006B24
        public SymData sym_data_member { get; }

        // Token: 0x17000010 RID: 16
        // (get) Token: 0x060000B0 RID: 176 RVA: 0x00007B2C File Offset: 0x00006B2C
        public List<uint> list_typeid { get; }

        // Token: 0x17000011 RID: 17
        // (get) Token: 0x060000B1 RID: 177 RVA: 0x00007B34 File Offset: 0x00006B34
        // (set) Token: 0x060000B2 RID: 178 RVA: 0x00007B3C File Offset: 0x00006B3C
        public SymUdt sym_udt_dependency { get; set; }

        // Token: 0x060000B3 RID: 179 RVA: 0x00007B45 File Offset: 0x00006B45
        public override ulong GetOffset() {
            return sym_data_member.TypeOffset;
        }

        // Token: 0x060000B4 RID: 180 RVA: 0x00007B53 File Offset: 0x00006B53
        public override ulong GetLength() {
            return GetFirstSymType().LengthOfType;
        }

        // Token: 0x060000B5 RID: 181 RVA: 0x00007B60 File Offset: 0x00006B60
        public Symbol GetFirstSymType() {
            if (list_typeid != null && list_typeid.Count > 0) return mod_sym.list_symbol.GetSymByTypeId(list_typeid[0]);
            return null;
        }

        // Token: 0x060000B6 RID: 182 RVA: 0x00007B98 File Offset: 0x00006B98
        public Symbol GetLastSymType() {
            if (list_typeid != null && list_typeid.Count > 0)
                return mod_sym.list_symbol.GetSymByTypeId(list_typeid[list_typeid.Count - 1]);
            return null;
        }

        // Token: 0x060000B7 RID: 183 RVA: 0x00007BE5 File Offset: 0x00006BE5
        public Symbol GetSymTypeByIndex(uint index) {
            if (list_typeid != null && list_typeid.Count > 0)
                return mod_sym.list_symbol.GetSymByTypeId(list_typeid[(int) index]);
            return null;
        }

        // Token: 0x060000B8 RID: 184 RVA: 0x00007C1C File Offset: 0x00006C1C
        public uint GetTagByIndex(uint index) {
            if (list_typeid != null && list_typeid.Count > 0) {
                var symByTypeId = mod_sym.list_symbol.GetSymByTypeId(list_typeid[(int) index]);
                if (symByTypeId != null) return symByTypeId.SymTag;
            }

            return uint.MaxValue;
        }

        // Token: 0x060000B9 RID: 185 RVA: 0x00007C68 File Offset: 0x00006C68
        public void Create_list_type() {
            var flag = false;
            sym_udt_dependency = null;
            if (sym_data_member != null)
                for (var symByTypeId = mod_sym.list_symbol.GetSymByTypeId(sym_data_member.TypeId_next);
                    symByTypeId != null;
                    symByTypeId = mod_sym.list_symbol.GetSymByTypeId(symByTypeId.TypeId_next)) {
                    if (symByTypeId.SymTag == 11U && !flag)
                        sym_udt_dependency                   = (SymUdt) symByTypeId;
                    else if (symByTypeId.SymTag == 14U) flag = true;
                    list_typeid.Add(symByTypeId.TypeId);
                }
        }
    }
}